<template>
  <div class="goodsss">
    <el-container>
      <el-header>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/ssss' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>商品管理</el-breadcrumb-item>
          <el-breadcrumb-item>商品列表</el-breadcrumb-item>
        </el-breadcrumb>
      </el-header>
      <el-main>
        <div class="goods-ce">
          <el-input v-model="data.query" placeholder="请输入内容"></el-input>

          <el-button icon="el-icon-search" @click="sousuo"></el-button>
          <router-link to="/goods/add">
            <el-button type="primary" class="goods-tian">添加商品</el-button>
          </router-link>
        </div>
        <el-table :data="list" border style="width: 100%">
          <el-table-column prop="" label="序号">
            <template slot-scope="{ $index }">
              {{ $index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="goods_name" label="商品名称">
          </el-table-column>
          <el-table-column prop="goods_price" label="商品价格(元)">
          </el-table-column>
          <el-table-column prop="goods_weight" label="商品重量">
          </el-table-column>
          <el-table-column prop="address" label="创建时间"
            >1970-01-18 20:37:38
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="{ row }">
              <!-- 修改按钮 -->
              <el-button
                @click="handleClick(scope.row)"
                type="primary"
                size="small"
                icon="el-icon-edit"
              ></el-button>
              <!-- 删除按钮 -->
              <el-button
                type="danger"
                size="small"
                icon="el-icon-delete"
                @click="shanchu(row)"
              ></el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </el-main>
    </el-container>
  </div>
</template>
<script>
import { huoQuGoods, shanChuGoods } from '@/api/goods'
export default {
  name: 'GoodsA',
  data () {
    return {
      input: '',
      data: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      list: [],
      currentPage: 1,
      total: 0
    }
  },
  created () {
    this.fss()
  },
  computed: {
  },
  methods: {
    async fss () {
      const res = await huoQuGoods(this.data)
      console.log(res);
      this.list = res.data.goods
      this.total = res.data.total
      this.$message.success('获取商品列表成功')
    },
    handleClick (row) {
      console.log(row);
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`);
      this.data.pagesize = val
      this.fss()
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`);
      this.data.pagenum = val
      this.fss()
    },
    async sousuo () {
      const res = await huoQuGoods(this.data)
      this.fss()
    },
    async shanchu (row) {
      // console.log(row);
      const res = await shanChuGoods(row.goods_id)
      console.log(res);
      this.$message.success('删除成功')
      this.fss()
    }
  }
}
</script>
<style lang='less'  scoped>
.goods-ce {
  display: flex;

  .goods-tian {
    margin-left: 50px;
    margin-right: 600px;
  }
}
.goodsss {

}
</style>
